<?php

/**
 *  文件处理
 */
$userName = 'pack';

$packPath = '/Users/'.$userName.'/workspace/workCodes/socket/Applications/AutoPack/ipa';
$confPath = '/Users/'.$userName.'/workspace/workCodes/socket/Applications/AutoPack/mobileprovision';

file_put_contents('filename.log', var_export($_FILES)."\n", FILE_APPEND);

if ($_FILES["fileToUpload"]["error"] > 0) {
    $json = array('state'=>'ERROR','name'=>$_FILES["fileToUpload"]["name"],'info'=>'文件读取错误','url'=>'');
}

    
if(substr($_FILES["fileToUpload"]['name'], -3) == 'ipa') {
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $packPath.'/' . $_FILES["fileToUpload"]["name"]);
} else {
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $confPath.'/' . $_FILES["fileToUpload"]["name"]);
}  
$json = array(
    'state'=>'SUCCESS',
    'name'=>$_FILES["fileToUpload"]["name"],
    'info'=>'文件上传成功',
    'url'=>'http://'. $_SERVER['SERVER_NAME'] .'/'. $_FILES["fileToUpload"]["name"]
);
$json = json_encode($json);
$callback = 'http://demo.giles.cc/index.html';
echo '<script type="text/javascript">window.top.'. $callback.'('. $json .')</script>';
?>